<?php
namespace App\Http\Controllers\Login;
use App\Http\Controllers\Controller;
use App\Models\TalentModels\Talent;
use Illuminate\Http\Request;
use App\Http\Controllers\ApiBaseController;
class TalentController extends ApiBaseController{
	
	public function __construct(Request $request){
        $this->parames = $request->all();
    }
	
	//审核列表
	function index(){
		$Talent=new Talent();
		$indList=$Talent->selectInd();
		return view('login/talent/index',['talent_list_index'=>true,'indList'=>$indList]);
	}
	
	//达人列表
	function info(){
		$Talent=new Talent();
		$indList=$Talent->selectInd();
		return view('login/talent/info',['talent_list_info'=>true,'indList'=>$indList]);
	}
	
	//列表拉取
	function dataList(){
		$Talent=new Talent();
		$result=$Talent->selectData($this->parames);
		exit(json_encode($result));
	}

	//审核操作
	function save(){
		$kid=isset($this->parames['kid']) ? intval($this->parames['kid']) : 0;
		$status=isset($this->parames['status']) ? intval($this->parames['status']) : -2;
		$remark=isset($this->parames['remark']) ? $this->parames['remark'] : '';
		if(!$kid){$this->returnJson(1,'数据错误');}
		
		$Talent=new Talent();
		$data=array(
			'tl_status'=>$status,
			'tl_shdate'=>date('Y-m-d H:i:s',time()),
			'tl_remark'=>$remark
		);
		$re=$Talent->updateTal($kid,$data);
		$re ? $this->returnJson(0,'操作成功') : $this->returnJson(1,'操作失败');
	}
	
	//状态修改
	function statusUp(){
		$kid=isset($this->parames['kid']) ? intval($this->parames['kid']) : 0;
		$status=isset($this->parames['status']) ? intval($this->parames['status']) : 0;
		
		$Talent=new Talent();
		$data=array(
			'tl_status'=>$status,
			'tl_update'=>date('Y-m-d H:i:s',time()),
		);
		$re=$Talent->updateTal($kid,$data);
		$re ? $this->returnJson(0,'修改成功') : $this->returnJson(1,'修改失败');
	}
	
	//删除操作
	function stdelete(){
		$kid=isset($this->parames['kid']) ? intval($this->parames['kid']) : 0;
		
		$Talent=new Talent();
		$data=[
			'tl_status'=>-1,
			'tl_update'=>date('Y-m-d H:i:s',time()),
		];
		$re=$Talent->db_update('',$kid,$data);
		$re ? $this->returnJson(0,'删除成功') : $this->returnJson(1,'删除失败');
	}
	
	//添加达人
	function addList(){
		$Talent=new Talent();
		$tl_uid=isset($this->parames['tl_uid']) ? $this->parames['tl_uid'] : '';
		$tl_uname=isset($this->parames['tl_uname']) ? $this->parames['tl_uname'] : '';
		$tl_tell=isset($this->parames['tl_tell']) ? $this->parames['tl_tell'] : '';
		$tl_type=isset($this->parames['tl_type']) ? intval($this->parames['tl_type']) : 0;
		
		!$tl_uid ? $this->returnJson(1,'请输入抖音号') : '';
		$chackUid=$Talent->chackUid($tl_uid);
		$chackUid ? $this->returnJson(1,'该抖音号已存在') : '';
		
		!$tl_uname ? $this->returnJson(1,'请输入昵称') : '';
		
		$checkUmobile=\App\Components\Tools::checkUmobile($tl_tell);
		!$checkUmobile ? $this->returnJson(1,'请输入正确的手机号') : '';
		$chackTell=$Talent->chackTell($tl_tell);
		$chackTell ? $this->returnJson(1,'该手机号已存在') : '';
		
		!$tl_type ? $this->returnJson(1,'请选择行业') : '';
		
		$data=array(
			'tl_uid'=>htmlspecialchars($tl_uid,ENT_QUOTES),
			'tl_uname'=>htmlspecialchars($tl_uname,ENT_QUOTES),
			'tl_uimg'=>"/images/default.png",
			'tl_type'=>$tl_type,
			'tl_status'=>1,
			'tl_created'=>date('Y-m-d H:i:s',time()),
			'tl_tell'=>$tl_tell,
		);
		// echo "<pre/>";print_r($data);exit;
		$re=$Talent->insertTal($data);
		
		$re ? $this->returnJson(0,'添加成功') : $this->returnJson(1,'添加失败');
	}
	
	//达人数据修改
	function saveNum(){
		$Talent=new Talent();
		$kid=isset($this->parames['kid']) ? intval($this->parames['kid']) : $this->returnJson(1,'参数错误');
		$fans=isset($this->parames['fans']) ? intval($this->parames['fans']) : $this->returnJson(1,'参数错误');
		$play=isset($this->parames['play']) ? intval($this->parames['play']) : $this->returnJson(1,'参数错误');
        $tl_type=isset($this->parames['tl_type']) ? intval($this->parames['tl_type']) : $this->returnJson(1,'参数错误');
        $tl_uname=$this->parames['uname'];
		$data=[
		    'tl_uname'=>$tl_uname,
			'tl_fans'=>$fans,
			'tl_play'=>$play,
            'tl_type'=>$tl_type,
		];
		
		$re=$Talent->db_update('',$kid,$data);
		$re ? $this->returnJson(0,'修改成功') : $this->returnJson(1,'修改失败');
	}
	
	
	
	
}